# import os
# import cv2
import numpy as np

# from micaps import Micaps

colors = [
    [10, 20, 250],
    [20, 40, 244],
    [30, 60, 238],
    [40, 80, 232],
    [50, 60, 226],
    [59, 126, 219],
    [78, 138, 221],
    [97, 150, 224],
    [116, 163, 226],
    [135, 175, 229],
    [155, 188, 232],
    [154, 196, 220],
    [152, 214, 196],
    [153, 205, 208],
    [152, 214, 196],
    [151, 232, 173],
    [215, 222, 126],
    [234, 219, 112],
    [244, 217, 99],
    [250, 204, 79],
    [247, 180, 45],
    [241, 155, 0],
    [241, 147, 3],
    [239, 117, 17],
    [238, 102, 24],
    [238, 88, 31],
    [231, 75, 26],
    [224, 63, 22],
    [217, 51, 18],
    [208, 36, 14],
    [194, 0, 3],
    [181, 1, 9],
    [169, 2, 16],
    [138, 5, 25],
    [111, 0, 21],
    [80, 0, 15],
]


def ImColor_tm(im):
    imc = np.zeros((im.shape[0], im.shape[1], 3))
    imc[:, :] = [0, 0, 255]
    for i, l in enumerate(range(-30, 42, 2)):
        imc[im > l] = colors[i][::-1]

    return imc.astype('uint8')


def ImColor_tp(im):
    imc = np.zeros((im.shape[0], im.shape[1], 3))
    imc[:, :] = [215, 215, 215]
    imc[im > 0.1] = [152, 251, 152]
    imc[im > 10] = [64, 189, 64]
    imc[im > 25] = [92, 172, 238]
    imc[im > 50] = [0, 0, 255]
    imc[im > 100] = [238, 0, 238]

    return imc.astype('uint8')


def ImColor_tp_1hour(im):
    imc = np.zeros((im.shape[0], im.shape[1], 3))
    imc[:, :] = [215, 215, 215]
    imc[im > 0.1] = [152, 251, 152]
    imc[im > 1.5] = [64, 189, 64]
    imc[im > 7] = [92, 172, 238]
    imc[im > 15] = [0, 0, 255]
    imc[im > 40] = [238, 0, 238]

    return imc.astype('uint8')


def ImColor_tp_12mins(im):
    imc = np.zeros((im.shape[0], im.shape[1], 3))
    imc[:, :] = [215, 215, 215]
    imc[im > 0.1] = [152, 251, 152]
    imc[im > 1] = [64, 189, 64]
    imc[im > 5] = [92, 172, 238]
    imc[im > 10] = [0, 0, 255]
    imc[im > 15] = [238, 0, 238]

    return imc.astype('uint8')

# if __name__ == '__main__':
#     micaps = Micaps("data/21030208.024")
#     scMi = micaps.read()
#     scmoc = np.load('data/201901010800_024.npy') - 273.15
#     cldas = np.load('data/21030208.npy') - 273.15
#     # array_cp = array.copy()[::-1,:]
#     aa = np.loadtxt("240", encoding='GBK', skiprows=2).transpose()
#
#     img_scmicaps = ImColor_tm(scMi)
#     # img_scmocnpy = ImColor_tm(aa)
#     img_cldas = ImColor_tm(cldas)
#
#     cv2.imshow("scmicaps", img_scmicaps)
#     # cv2.imshow('scmocnpy', img_scmocnpy)
#     cv2.imshow('cldas', img_cldas)
#     cv2.waitKey()
